package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.ReservationDto;
import com.zzyl.service.CustomerReservationService;
import com.zzyl.utils.UserThreadLocal;
import com.zzyl.vo.ReservationVo;
import com.zzyl.vo.TimeCountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description CustomerReservationController
 * @Author Lwj
 * @Date 2024-08-31-16:28
 */
@RestController
@RequestMapping("/customer/reservation")
@Slf4j
@Api(tags = "参观预约接口")
public class CustomerReservationController extends BaseController {
    @Autowired
    private CustomerReservationService customerReservationService;

    @GetMapping("/cancelled-count")
    @ApiOperation(value = "查询取消预约数量")
    public ResponseResult<Integer> getCount() {
        log.info("查询取消预约数量!");
        Long updateBy = UserThreadLocal.getUserId();
        Integer count = customerReservationService.getCount(updateBy);
        return success(count);
    }

    /**
     * 查询每个时间段剩余预约次数
     *
     * @param time
     * @return
     */
    @GetMapping("/countByTime")
    @ApiOperation(value = "查询每个时间段剩余预约次数")
    public ResponseResult<TimeCountVo> countBytime(@RequestParam @ApiParam(value = "时间段") Long time) {
        log.info("查询每个{}时间段剩余预约次数", time);
        List<TimeCountVo> timeCountVo = customerReservationService.countBytime(time);
        return success(timeCountVo);
    }

    /**
     * 新增预约
     *
     * @param reservationDto
     * @return
     */
    @PostMapping
    @ApiOperation(value = "新增预约")
    public ResponseResult add(@RequestBody ReservationDto reservationDto) {
        log.info("新增预约{}", reservationDto);
        customerReservationService.add(reservationDto);
        return success();
    }

    /**
     * 分页查询
     *
     * @param name
     * @param pageNumb
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询")
    public ResponseResult<PageResponse<ReservationVo>> getPage(
            @ApiParam(value = "预约人") String name,
            @ApiParam(value = "当前页码") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNumb,
            @ApiParam(value = "每页显示数量") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @ApiParam(value = "状态：0-禁用,1-启用") Integer status) {
        log.info("分页查询");
        PageResponse<ReservationVo> reservationVo = customerReservationService.getPage(name, pageNumb, pageSize, status);
        return success(reservationVo);
    }


    /**
     * 取消预约
     *
     * @param id
     * @return
     */
    @PutMapping("/{id}/cancel")
    @ApiOperation(value = "取消预约")
    public ResponseResult cancle(@PathVariable @ApiParam(value = "取消预约的id") Long id) {
        log.info("取消预约{}", id);
        customerReservationService.cancle(id);
        return success();
    }
}
